package com.my.hzb.order.quartz;

import java.util.Date;
import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.framelib.utils.Page;
import com.my.hzb.entiy.Orders;
import com.my.hzb.order.ctrl.OrderOptCtrl;
import com.my.hzb.order.service.OrderService;
import com.my.hzb.pro.service.ProductService;

public class ProStockQuartz {

	private static final Logger log = LogManager.getLogger(ProStockQuartz.class);
	@Autowired
	private OrderService orderService;
	@Autowired
	private ProductService productService;
	
	public void controlStock(){
		Orders query = new Orders();
		query.setStatus(0);
		List<Orders> list = orderService.find(query,new Page(1,2000));
		if(null!=list&&list.size()>0){
			log.info("order项目的定时器查询="+list.size());
			for(Orders order:list){
				if((order.getUpdateTime().getTime()-new Date().getTime())/1000>=100){
					int count = productService.updateStock(order.getProId(), 1, order.getSum());
					if(count>0){
						order.setStatus(3);
						order.setUpdateTime(new Date());
						orderService.update(order);
					}
				}
			}
		}
	}
}
